package com.action.login;

import java.util.*;
import com.opensymphony.xwork2.ActionSupport;
import com.db.login.JoinManager;

public class JoinAction {

	private String id;
	private String pw1;
	private String pw2;
	private String name;
	private String ju1;
	private String ju2;
	private String tel1;
	private String tel2;
	private String tel3;
	private String email;
	private String message;
	private String message2;
	private JoinManager join;

	public JoinManager getJoin() {
		return join;
	}

	public void setJoin(JoinManager join) {
		this.join = join;
	}

	public String getMessage2() {
		return message2;
	}

	public void setMessage2(String message2) {
		this.message2 = message2;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getPw1() {
		return pw1;
	}

	public void setPw1(String pw1) {
		this.pw1 = pw1;
	}

	public String getPw2() {
		return pw2;
	}

	public void setPw2(String pw2) {
		this.pw2 = pw2;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getJu1() {
		return ju1;
	}

	public void setJu1(String ju1) {
		this.ju1 = ju1;
	}

	public String getJu2() {
		return ju2;
	}

	public void setJu2(String ju2) {
		this.ju2 = ju2;
	}

	public String getTel1() {
		return tel1;
	}

	public void setTel1(String tel1) {
		this.tel1 = tel1;
	}

	public String getTel2() {
		return tel2;
	}

	public void setTel2(String tel2) {
		this.tel2 = tel2;
	}

	public String getTel3() {
		return tel3;
	}

	public void setTel3(String tel3) {
		this.tel3 = tel3;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String execute() throws Exception {

		String jumin = ju1 + ju2;
		String tel = tel1 + tel2 + tel3;

		int result1;
		result1 = join.IdCheck(id);

		if (id.equals("")) {
			message = "id를 입력하세요";
			return "fail";
		}
		if (pw1.equals("")) {
			message = "패스워드를 입력하세요";
			return "fail";
		}
		if (pw2.equals("")) {
			message = "패스워드 확인을 입력하세요";
			return "fail";
		}
		if (pw1.equals(pw2) == false) {
			message = "패스워드가 일치하지 않습니다.";
			return "fail";
		}
		if (tel2.equals("")) {
			message = "전화번호를 입력하여 주세요";
			return "fail";
		}
		if (result1 != 0) {
			// addActionError("�̹� �����ϴ� id �Դϴ�.");
			message = "입력하신 아이디는 다른 회원이 사용하고 있습니다.";
			return "fail";
		} else {

			Map map = new HashMap();
			map.put("id", id);
			map.put("pwd", pw1);
			map.put("name", name);
			map.put("jubun", jumin);
			map.put("tel", tel);
			map.put("email", email);

			join.OkJoin(map);
			return "success";
		}
	}

	public String JuminCk() throws Exception {

		String jumin = ju1 + ju2;

		int result;
		result = join.JuminCheck(jumin);

		if (name.equals("")) {
			message = "이름을 입력하여주세요";

			return "fail";

		}
		if (jumin.equals("")) {
			message = "주민번호를 입력하세요";

			return "fail";

		}
		if (jumin.length() != 13) {
			message = "주민번호는 13자리 입니다.";

			return "fail";

		}
		if (result != 0) {
			message = "이미 가입 하셧습니다.";

			return "fail";

		} else {
			message2 = "";
			return "success";
		}

	}

}
